//
//  WBUserDataHelper.swift
//  Swift-WB
//
//  Created by lxy on 2017/6/12.
//  Copyright © 2017年 lixiya. All rights reserved.
//

import UIKit
import SwiftyJSON
import HandyJSON

class WBUserDataHelper: NSObject {

    static let shared = WBUserDataHelper()
    
    private override init() {}
    
    lazy var userAccount = WBUserAccount()
    
    // 微博授权认证
    func wbOAuth(_ code: String, success: @escaping Success, failure: @escaping Failure) {
        let params = ["client_id":WBAppKey,"client_secret":WBAppSecret,"grant_type":"authorization_code","code":code,"redirect_uri":WBRedirectURL]
        
        HttpsTools.shared.post(url: WBOAuthUrl, parameters: params, success: { (response) in
            
            if let userAccount = JSONDeserializer<WBUserAccount>.deserializeFrom(json: JSON(response).description) {
                self.userAccount = userAccount
            }
            
        }, failure: { (error) in
            failure(error)
        })
        
        
    }


}
